package com.software.notification.utils;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.graphics.BitmapFactory;

import androidx.core.app.NotificationCompat;

import com.software.notification.R;

public class NotifyUtil {
    private static final String CHANNEL_ID = "wechat";
    private static final String CHANNEL_NAME = "微信";
    private NotificationManager manager;
    private Context context;
    public NotifyUtil(Context context, Integer importance){
        this.context = context;
        manager = (NotificationManager) context.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);

        //创建渠道
        createNotificationChannel(importance);
    }

    private void createNotificationChannel(Integer importance) {
        NotificationChannel channel = new NotificationChannel(
                CHANNEL_ID,
                CHANNEL_NAME,
                importance
        );
        //设置声音
        channel.setSound(null, null);
        //图标上是否有小红点
        channel.setShowBadge(true);
        //是否跑马灯
        channel.enableLights(true);
        //推送是否震动
        channel.enableVibration(true);
        //通知栏是否可见
        channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
        manager.createNotificationChannel(channel);
    }

    public void sendNotify(String title, String message, Integer smallIcon, Integer largeIcon){
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID);
        builder.setSmallIcon(smallIcon)
                .setContentTitle(title)
                .setContentText(message)
                .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), largeIcon));
        //进度条
        builder.setProgress(100, 60, false);
        //进度条显示计时器
        builder.setUsesChronometer(true);
        Notification notification = builder.build();
        manager.notify(R.string.app_name, notification);
    }
}
